<template>
  <div class="admin-dashboard">
    <el-container>
      <el-aside width="200px">
        <el-menu
          :default-active="activeMenu"
          class="admin-menu"
          @select="handleMenuSelect"
        >
          <el-menu-item index="/admin/users">
            <el-icon><User /></el-icon>
            <span>用户管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/data-tables">
            <el-icon><Grid /></el-icon>
            <span>数据中心</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { User, Grid } from '@element-plus/icons-vue';

const router = useRouter();
const route = useRoute();
const activeMenu = ref('');

onMounted(() => {
  activeMenu.value = route.path;
});

const handleMenuSelect = (index) => {
  router.push(index);
};
</script>

<style scoped>
.admin-dashboard {
  height: 100vh;
}

.el-container {
  height: 100%;
}

.el-aside {
  background-color: #304156;
  color: #fff;
}

.admin-menu {
  border-right: none;
  background-color: transparent;
}

.el-menu-item {
  color: #bfcbd9;
}

.el-menu-item:hover {
  color: #fff;
}

.el-menu-item.is-active {
  color: #409EFF;
  background-color: #263445;
}

.el-main {
  padding: 20px;
  background-color: #f0f2f5;
}
</style>